/**
 * 
 */
package br.com.games.daedal.imp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import br.com.games.daedal.Box;
import br.com.games.daedal.Vertex;
import br.com.games.hefesto.Team;

/**
 * Arestas do Jogo
 * 
 * @since 2013
 * @author <a href="mailto:fernando.schindler@gmail.com">Fernando Schindler</a>
 */
public class DaedalVertex implements Vertex {

	/**
	 * 
	 * @param owner
	 */
	public DaedalVertex(VertexType type, int x, int y) {
		this.location = new int[4];
		this.oweners = new ArrayList<Box>();

		this.location[0] = x;
		this.location[1] = y;

		if (type.equals(VertexType.HORIZONTAL)) {
			this.location[2] = x + 1;
			this.location[3] = y;
		} else {
			this.location[2] = x;
			this.location[3] = y + 1;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#isActive()
	 */
	@Override
	public Boolean isActive() {
		return this.active;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#setActive(java.lang.Boolean)
	 */
	@Override
	public void setActive(Boolean value) {
		this.active = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#getOweners()
	 */
	@Override
	public List<Box> getOweners() {
		return oweners;
	}

	/**
	 * 
	 * @param box
	 */
	public void addOwener(Box box) {
		this.oweners.add(box);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#getLocation()
	 */
	@Override
	public int[] getLocation() {
		return location;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		boolean result = false;

		if (obj instanceof DaedalVertex) {
			result = Arrays.equals(location, ((DaedalVertex) obj).location);
		}

		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return Arrays.toString(location);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#setAnalyzeMode(java.lang.Boolean)
	 */
	@Override
	public void setAnalyzeMode(Boolean value) {
		this.underAnalyze = value;
		this.analyze = active;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#valueBeforeAnalise()
	 */
	@Override
	public Boolean valueBeforeAnalise() {
		return underAnalyze ? analyze : isActive();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#getTeam()
	 */
	@Override
	public Team getTeam() {
		return this.team;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.games.daedal.Vertex#setTeam(br.com.games.hefesto.Team)
	 */
	@Override
	public void setTeam(Team team) {
		this.team = team;
	}

	/**
	 * Campos privados
	 */
	private Boolean active = false;
	private Boolean underAnalyze = false;
	private Boolean analyze = false;
	private List<Box> oweners;
	private int[] location;
	private Team team;
}
